<?php

namespace Apps\AppApi\Method\MyBranch;

use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\BeautyParlorInteractive;
use Apps\Common\Libs\PicUrl;


/**
 * 获取美容院的互动列表
 * @author      545
 * @date        2016年4月18日
 * @version     2.0.2
 * @copyright   Copyright 2015 meelier.com
 */
class BpInteractiveList extends BaseMethod
{
    

    public function run()
    {
        //验证是否登录
        if(false == $this->verifyUserAuth()){
            return false;
        }
        
        $bp_id = $this->getDataItem('bp_id',0);
        if ($bp_id<=0){
            return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR,"美容院id不能为空");
        }
        //获取分页参数
        $page = intval($this->getDataItem('page',1));
        $limit = $this->getConfig()->limit;
        $offset = ($page-1)*$limit;
        
        //获取列表
        $InteractiveLists = BeautyParlorInteractive::query()
                            ->columns('id,content,pics,state,addtime')
                            ->where("state = 1 AND bp_id = {$bp_id}")
                            ->orderBy("addtime DESC")
                            ->limit($limit, $offset)
                            ->execute()->toArray();
        //处理图片
        foreach ($InteractiveLists as $k => $val) {
            
            $InteractiveLists[$k]['content'] = unserialize(base64_decode($val['content'])) ?: $val['content'];
            if (json_decode($val['pics'], true)) {
                $question_pics = PicUrl::Question(json_decode($val['pics'], true), $this->getDi());
                $InteractiveLists[$k]['pics'] = $question_pics;
            }else {
                $InteractiveLists[$k]['pics'] = [];
            }
            
        }
        //设置返回结果
    	return $this->setResult($InteractiveLists);
    }
    
}